package com.hlx.controller;

import com.hlx.enumeration.TypeEnum;
import com.hlx.service.ChatHistoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequiredArgsConstructor
@RequestMapping("/ai/service")
public class CustomerServiceController {

	private final ChatClient serviceChatClient;

	private final ChatHistoryService chatHistoryService;

	@GetMapping(produces = "text/html; charset=utf-8")
	public Flux<String> service(String prompt, String chatId){
		chatHistoryService.save(TypeEnum.SERVICE.getValue(), chatId);
		return serviceChatClient
				.prompt()
				.user(prompt)
				.advisors(a -> a.param(ChatMemory.CONVERSATION_ID, chatId))
				.stream()
				.content();
	}
}
